CMAKE_MINIMUM_REQUIRED(VERSION 3.0)

PROJECT(firmware-utils C)
INCLUDE(GNUInstallDirs)
INCLUDE(FindZLIB)
INCLUDE(FindOpenSSL)

IF(NOT ZLIB_FOUND)
  MESSAGE(FATAL_ERROR "Unable to find zlib library.")
ENDIF()

IF(NOT OPENSSL_FOUND)
  MESSAGE(FATAL_ERROR "Unable to find OpenSSL library.")
ENDIF()

ADD_DEFINITIONS(-Wall -Wno-unused-parameter)

MACRO(FW_UTIL util deps extra_cflags libs)
  ADD_EXECUTABLE(${util} src/${util}.c ${deps})
  INSTALL(TARGETS ${util} RUNTIME)
  IF(NOT "${extra_cflags}" STREQUAL "")
    SET_TARGET_PROPERTIES(${util} PROPERTIES COMPILE_FLAGS ${extra_cflags})
  ENDIF()
  IF(NOT "${libs}" STREQUAL "")
    TARGET_LINK_LIBRARIES(${util} ${libs})
  ENDIF()
ENDMACRO(FW_UTIL)

FW_UTIL(add_header "" "" "")
FW_UTIL(addpattern "" "" "")
FW_UTIL(asustrx "" "" "")
FW_UTIL(asusuimage "" "" "${ZLIB_LIBRARIES}")
FW_UTIL(avm-wasp-checksum "" --std=gnu99 "")
FW_UTIL(bcm4908asus "" "" "")
FW_UTIL(bcm4908kernel "" "" "")
FW_UTIL(bcmblob "" "" "")
FW_UTIL(bcmclm "" "" "")
FW_UTIL(buffalo-enc src/buffalo-lib.c "" "")
FW_UTIL(buffalo-tag src/buffalo-lib.c "" "")
FW_UTIL(buffalo-tftp src/buffalo-lib.c "" "")
FW_UTIL(cros-vbutil "" "" "${OPENSSL_CRYPTO_LIBRARIES}")
FW_UTIL(dgfirmware "" "" "")
FW_UTIL(dgn3500sum "" "" "")
FW_UTIL(dlink-sge-image "" "" "${OPENSSL_CRYPTO_LIBRARIES}")
FW_UTIL(dns313-header "" "" "")
FW_UTIL(edimax_fw_header "" "" "")
FW_UTIL(encode_crc "" "" "")
FW_UTIL(fix-u-media-header src/cyg_crc32.c "" "")
FW_UTIL(hcsmakeimage src/bcmalgo.c "" "")
FW_UTIL(imagetag "src/imagetag_cmdline.c;src/cyg_crc32.c" "" "")
FW_UTIL(iptime-crc32 src/cyg_crc32.c "" "")
FW_UTIL(iptime-naspkg "" "" "")
FW_UTIL(jcgimage "" "" "${ZLIB_LIBRARIES}")
FW_UTIL(linksys-addfwhdr src/cyg_crc32.c "" "")
FW_UTIL(lxlfw "" "" "")
FW_UTIL(lzma2eva "" "" "${ZLIB_LIBRARIES}")
FW_UTIL(makeamitbin "" "" "")
FW_UTIL(mkbrncmdline "" "" "")
FW_UTIL(mkbrnimg "" "" "")
FW_UTIL(mkbuffaloimg "" "" "")
FW_UTIL(mkcameofw "" "" "")
FW_UTIL(mkcasfw "" "" "")
FW_UTIL(mkchkimg "" "" "")
FW_UTIL(mkcsysimg "" "" "")
FW_UTIL(mkdapimg "" "" "")
FW_UTIL(mkdapimg2 "" "" "")
FW_UTIL(mkdhpimg src/buffalo-lib.c "" "")
FW_UTIL(mkdlinkfw src/mkdlinkfw-lib.c --std=c99 "${ZLIB_LIBRARIES}")
FW_UTIL(mkdniimg "" "" "")
FW_UTIL(mkedimaximg "" "" "")
FW_UTIL(mkfwimage "" "-Wextra -D_FILE_OFFSET_BITS=64" "${ZLIB_LIBRARIES}")
FW_UTIL(mkfwimage2 "" "" "${ZLIB_LIBRARIES}")
FW_UTIL(mkh3cimg "" "" "")
FW_UTIL(mkh3cvfs "" "" "")
FW_UTIL(mkheader_gemtek "" "" "${ZLIB_LIBRARIES}")
FW_UTIL(mkhilinkfw "" "" "${OPENSSL_CRYPTO_LIBRARIES}")
FW_UTIL(mkmerakifw src/sha1.c "" "")
FW_UTIL(mkmerakifw-old "" "" "")
FW_UTIL(mkmylofw "" "" "")
FW_UTIL(mkplanexfw src/sha1.c "" "")
FW_UTIL(mkporayfw "" "" "")
FW_UTIL(mkrasimage "" --std=gnu99 "")
FW_UTIL(mkrtn56uimg "" "" "${ZLIB_LIBRARIES}")
FW_UTIL(mksenaofw src/md5.c --std=gnu99 "")
FW_UTIL(mksercommfw "" "" "")
FW_UTIL(mktitanimg "" "" "")
FW_UTIL(mktplinkfw "src/mktplinkfw-lib.c;src/md5.c" -fgnu89-inline "")
FW_UTIL(mktplinkfw2 "src/mktplinkfw-lib.c;src/md5.c" -fgnu89-inline "")
FW_UTIL(mkwrggimg src/md5.c "" "")
FW_UTIL(mkwrgimg src/md5.c "" "")
FW_UTIL(mkzcfw src/cyg_crc32.c "" "")
FW_UTIL(mkzynfw "" "" "")
FW_UTIL(mkzyxelzldfw src/md5.c "" "")
FW_UTIL(motorola-bin "" "" "")
FW_UTIL(nand_ecc "" "" "")
FW_UTIL(nec-enc "" --std=gnu99 "")
FW_UTIL(nec-usbatermfw "" -D_DEFAULT_SOURCE "")
FW_UTIL(nosimg-enc "" --std=gnu99 "")
FW_UTIL(osbridge-crc "" "" "")
FW_UTIL(oseama src/md5.c "" "")
FW_UTIL(otrx "" "" "")
FW_UTIL(pc1crypt "" "" "")
FW_UTIL(ptgen src/cyg_crc32.c "" "")
FW_UTIL(seama src/md5.c "" "")
FW_UTIL(sign_dlink_ru src/md5.c "" "")
FW_UTIL(spw303v "" "" "")
FW_UTIL(srec2bin "" "" "")
FW_UTIL(tplink-safeloader src/md5.c --std=gnu99 "")
FW_UTIL(trx "" "" "")
FW_UTIL(trx2edips "" "" "")
FW_UTIL(trx2usr "" "" "")
FW_UTIL(uimage_padhdr "" "" "${ZLIB_LIBRARIES}")
FW_UTIL(uimage_sgehdr "" "" "${ZLIB_LIBRARIES}")
FW_UTIL(wrt400n src/cyg_crc32.c "" "")
FW_UTIL(xiaomifw "" "" "")
FW_UTIL(xorimage "" "" "")
if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
  FW_UTIL(zycast "" "" "")
endif()
FW_UTIL(zyimage "" "" "")
FW_UTIL(zytrx "" "" "")
FW_UTIL(zyxbcm "" "" "")
